//just to try svn
#ifndef GENECAN_H
#define GENECAN_H


#include <string>
#include <vector>
#include <map>

#include "model.h"
using namespace std;


//********************************************************************
//Gene candidate is defined by a stop codon, it's from the stop to the 
//furtherest start plus upstream sequence. The length of the upstream 
//sequence is defined by the model parameter(lenth of spacer + length of
//motif + order). The first order nucleotide will not be included in the
//probability calculation.
//********************************************************************
typedef struct Start
{
	int pos;
	double score; // total score of this start being real start
	double codP; //coding probability from stop up to this start
	double forward;//forward probability up to this point (sum of all possible motif + noncoding)
	double non; //noncoding probability from (sequence boundary - order) up to this start
	
	double codH; //coding probability from stop up to this start
	
	double codLength; //log of length probability
	double nonLength;//log score of length probability of the upstream noncoding region
	double startCodon; //log score for start Codon usage (and maybe surronding sequence)
	double startPattern; //log score for start Codon and surronding sequences(-1 to +8)
	//**
	double codPotential;
	double avgcod;//cod/length
	double avgnon;
	double motif; //forward - non
	//**
};

class GeneCandidate {     

public:
        GeneCandidate(); // Constructor
        GeneCandidate(string line);         // Constructor, input is one line of .lst annotation, set predicted information

        void setGeneCan(string & seq, ModelFile & m); // set gene candidate sequence and all possible gene starts
		void calNoncoding(ModelFile & m);
		void calLocalNoncoding(ModelFile & m);
		void calMotif(ModelFile & m);
		void calCod(ModelFile & m); // catculate coding probability for each position, from gene stop to the furtherst start.
		void calLocalCod(ModelFile & m);
		void calForward(ModelFile & m);
		//void calLength(ModelFile & m, int upstreamPos);
		void calLength(ModelFile & m);
		void calStartCodon(ModelFile & m);
		void calStartPattern(ModelFile & m);
		void calCodPotential(ModelFile & m);
		Start getMaxStart();
		Start getOriginal();
      //  double get_codon_score(double * P_Q);
      //  double get_start_score(double * P_Q);
      //  double get_length_score(vector<double>& P_Q_length_logodd);

		vector<Start> starts;
		vector<double> noncoding; // log noncoding probability at each position
		vector<double> codingP; // log coding probability at each position
		vector<double> codingH; // log coding probability at each position
		vector<double> motif; //log motif probability at each position (PWM over noncoding)
        string id;
        char strand;
        int predicted_left;
        int predicted_right;
        int predicted_length;
        int predicted_class;
		int geneCan_left;
		int geneCan_right;
        string geneCan_seq; // seq represented by 0-3
		GeneCandidate *prev;// points to the left-side gene
		GeneCandidate *next;// points to the right-side gene

private:
        void seqToInt(string & seq);
}; 

#endif

double logOfSum(double p, double q);
double reverseSum(vector<double> & v, int l);